
#include "note.h"

NoteItem::NoteItem()
{
    clear();
}
NoteItem::~NoteItem()
{}
void    NoteItem::clear()
{
    _NoteType = NOTE;
    _Date = QDate::currentDate();
    _Time = QTime::currentTime();
    _Title.clear();
    _Progress = 0;
    _bClock = true;
    _ClockTime = _Time;
    _Remark.clear();
    _ReceiverList.clear();
}

NoteType NoteItem::getNoteType()
{
    return _NoteType;
}

QDate   NoteItem::getDate()
{
    return _Date;
}

QTime   NoteItem::getTime()
{
    return _Time;
}

QString NoteItem::getTitle()
{
    return _Title;
}

qint32  NoteItem::getProgress()
{
    return _Progress;
}

bool    NoteItem::getClocker()
{
    return _bClock;
}

QTime   NoteItem::getClockTime()
{
    return _ClockTime;
}

QString NoteItem::getRemark()
{
    return _Remark;
}

QStringList NoteItem::getReceiver()
{
    return _ReceiverList;
}


void    NoteItem::setNoteType(NoteType _type)
{
    _NoteType = _type;
}

void    NoteItem::setDate(QDate _date)
{
    _Date = _date;
}


void    NoteItem::setTime(QTime _time)
{
    _Time = _time;
}

void    NoteItem::setTitle(QString _title)
{
    _Title = _title;
}

void    NoteItem::setProgress(qint32 _progress)
{
    _Progress = _progress;
}

void    NoteItem::setClocker(bool _clockFlag)
{
    _bClock = _clockFlag;
}

void    NoteItem::setClockTime(QTime _clockTime)
{
    _ClockTime = _clockTime;
}

void    NoteItem::setRemark(QString _remark)
{
    _Remark = _remark;
}

void    NoteItem::setReceiver(QStringList _receiver)
{
    _ReceiverList = _receiver;
}

void    NoteItem::addReveiver(QString _oneReceiver)
{
    _ReceiverList<<_oneReceiver;
}

//**************define NoteItem Operations over*********************************

//**************define NoteItemOneDay*******************************************
NoteItemOneDay::NoteItemOneDay()
{

}
NoteItemOneDay::~NoteItemOneDay()
{}

void NoteItemOneDay::clear()
{
    _itemsOneDay.clear();
}

NoteItem NoteItemOneDay::getItem(QTime _key)
{
    return _itemsOneDay.find(_key.toString(DATE_FORMAT)).value();
}

NoteItem NoteItemOneDay::getItemByTitle(QString _title)
{
    QMap<QString,NoteItem>::const_iterator iter = _itemsOneDay.begin();
    NoteItem temp;
    while(iter!=_itemsOneDay.end())
    {
        temp = iter.value();
        if(_title == temp.getTitle())
            break;
         ++iter;
    }
    if(iter==_itemsOneDay.end())
        temp.clear();

    return temp;
}

NoteItem NoteItemOneDay::getTopItem()
{
    return _itemsOneDay.begin().value();
}

NoteItem NoteItemOneDay::getBottomItem()
{
    QMap<QString,NoteItem>::const_iterator iter = _itemsOneDay.end();
    --iter;
    return iter.value();
}

void NoteItemOneDay::addItem(NoteItem _item)
{
    _itemsOneDay.insert(_item.getTime().toString(Qt::ISODate),_item);
}

void NoteItemOneDay::addItem(QString _key,NoteItem _item)
{
    _itemsOneDay.insert(_key,_item);
}

void NoteItemOneDay::deleteItem(QTime _key)
{
    _itemsOneDay.erase(_itemsOneDay.find(_key.toString(Qt::ISODate)));

}

void NoteItemOneDay::deleteItemByTitle(QString _title)
{
    QMap<QString,NoteItem>::iterator iter = _itemsOneDay.begin();
    NoteItem temp;
    while(iter!=_itemsOneDay.end())
    {
        temp = iter.value();
        if(_title == temp.getTitle())
            break;
         ++iter;
    }
    if(iter!=_itemsOneDay.end())
        _itemsOneDay.erase(iter);
}

void NoteItemOneDay::updateItem(QTime _key,NoteItem _item)
{
    _itemsOneDay.insert(_key.toString(Qt::ISODate),_item);
}

qint32  NoteItemOneDay::getSize()
{
    return _itemsOneDay.size();
}

QMap<QString,NoteItem>::const_iterator NoteItemOneDay::constBegin()
{
    return _itemsOneDay.begin();
}

QMap<QString,NoteItem>::const_iterator NoteItemOneDay::constEnd()
{
    return _itemsOneDay.end();
}
//**************define NoteItemMap**********************************************
NoteItemMap::NoteItemMap()
{}
NoteItemMap::~NoteItemMap()
{}

void NoteItemMap::addItemOneDay(NoteItemOneDay _item)
{
    _itemMap.insert(_item.getTopItem().getDate().toString(DATE_FORMAT) , _item);

}

void NoteItemMap::deleteItemOneDay(QDate _date)
{
    _itemMap.erase(_itemMap.find(_date.toString(DATE_FORMAT)));
}

bool NoteItemMap::getItemOneDay(QDate _date,NoteItemOneDay &_itemOneday)
{
    _itemOneday.clear();//delete all elements in _itemOneday.
    QMap<QString,NoteItemOneDay>::const_iterator iter = _itemMap.find(_date.toString(DATE_FORMAT));
    if(iter != _itemMap.end())
    {
        _itemOneday = iter.value();
        return true;
    }
    return false;

}
QMap<QString,NoteItemOneDay>::const_iterator NoteItemMap::constBegin()
{
    return _itemMap.constBegin();
}

QMap<QString,NoteItemOneDay>::const_iterator NoteItemMap::constEnd()
{
    return _itemMap.constEnd();
}
qint32  NoteItemMap::getSize()
{
    return _itemMap.size();
}

void    NoteItemMap::clear()
{
    _itemMap.clear();
}
